<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="<?php echo base_url()?>themes/default/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="<?php echo base_url()?>themes/default/css/ace.min.css" />

<link rel="stylesheet" href="<?php echo base_url()?>themes/default/css/ace-skins.min.css" />

<link rel="stylesheet" href="<?php echo base_url()?>themes/default/css/font-awesome.min.css" />

<!-- jQuery 2.0.2 -->
<script src="<?php echo base_url()?>public/js/jquery-1.7.2.min.js"></script>
<!-- Bootstrap -->
<script src="<?php echo base_url()?>public/js/bootstrap.min.js" type="text/javascript"></script>
<script type="text/javascript" src="<?php echo base_url() ?>public/js/validform.js"></script>
<script type="text/javascript" src="<?php echo base_url() ?>public/js/plugins/layer/layer.js"></script>
</head>
<style>
body {
font-family: "Microsoft YaHei";
}
.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td{
padding:2px;
vertical-align:middle;
}
</style>
<body>
<div class="col_main"><!------右侧开始------>
	<!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">
        <!-- Main content -->
        <section class="content notices_box" style="border:none;">
			<div class="col-xs-12" style="padding:5px;overflow-x: hidden;">
				<div class="box">
    				<div class="box-body">
    				<form id="productform" role="form" action="<?php echo base_url() . 'admin/Upyun/choose_user_list/'.$coupon_id; ?>" method="get">
        				<div>
        				       姓名：<input type="text" name="user_name" value="<?php if (isset($user_name))echo $user_name;?>" />
        				       手机号码：<input type="text"  name="user_phone" value="<?php if (isset($user_phone))echo $user_phone;?>"/>
        				       角色状态：<select name="role_type">
	                            <option value="0" <?php if (isset($role_type)&&$role_type == 0)echo "selected";?>>全部</option>
								<option value="1" <?php if (isset($role_type)&&$role_type == 1)echo "selected";?>>客户</option>
								<option value="2" <?php if (isset($role_type)&&$role_type == 2)echo "selected";?>>机主</option>
							</select>
                           <br />
                            	所属加油站：<select name="gid" style="margin:5px;">
                                <option value="0" <?php if (empty($gid))echo "selected";?>>全部</option>
                                <?php foreach($gasstation as $k=>$v):?>
	                            <option value="<?php echo $v['id']?>" <?php if (isset($gid)&&$gid == $v['id'])echo "selected";?>><?php echo $v['gasstation_name']?></option>
								<?php endforeach;?>
							</select>
                            
        		    	<button type="submit" class="btn btn-xs btn-info">检索</button>
            		    </div>
    				</form>
    				<form id="form" role="form" action="<?php echo base_url() . 'admin/activity/release_confirm/'.$coupon_id; ?>" method="post">
                    <table class="table table-striped table-bordered">
                            <tbody>
                            <tr>
                            	  <th class="center" style="width: 5%;">
									<label>
										<input type="checkbox" class="ace" />
										<span class="lbl"></span>
									</label>
								  </th>
	                              <th>姓名</th>
	                              <th>手机号码</th>
	                              <th>性别</th>
	                              <th>角色状态</th>
                            </tr>
                            </tbody>
                            <tbody>
                            <?php if(is_array($result)&&count($result)>0){
	                            foreach ($result as $val){
	                            	echo '<tr>';
	                            	echo '<td class="center">
											<label>
												<input type="checkbox" class="ace" name="user_id[]" value="'.$val->id.'"/>
												<span class="lbl"></span>
											</label>
										  </td>';
	                            	echo '<td>'.$val->card_name.'</td>';
	                            	echo '<td>'.$val->login_name.'</td>';
	                            	echo '<td>'.$val->sex.'</td>';
	                            	if($val->role_type == 1){
                                		echo "<td>客户</td>";
                                	}elseif($val->role_type == 2){
                                		echo "<td>机主</td>";
                                	}
		                            echo '</tr>';
	                            }
                            }else{
                            	echo '<tr><td colspan="5">无数据</td></tr>';
                            }?>
                            </tbody>
                         </table>
                         </form>
                         </div>
                       <div class="box-footer clearfix">
	                       <?php if (isset($page))echo $page;?>
                       </div>
                       <div>
                       	   <button type="button" onclick="send_coupon();" class="btn btn-xs btn-info">确定发放</button>
                       </div>
                    </div>
				</div>
        </section><!-- /.content -->
    </aside><!-- /.right-side -->
</div>
<script type="text/javascript">
$(function(){
    $.Tipmsg.r=null;
    $("#form").Validform({
        tiptype:function(msg){
            layer.msg(msg);
        },
        tipSweep:true,
        ajaxPost:true,
        callback:function(data){
            if(data.status=="y"){
            	layer.msg('发放成功');
            }else{
            	layer.msg('发放失败');
            }
        }
    });
})
$('table th input:checkbox').on('click' , function(){
	var that = this;
	$(this).closest('table').find('tr > td:first-child input:checkbox')
	.each(function(){
		this.checked = that.checked;
		$(this).closest('tr').toggleClass('selected');
	});
});
function checkSelect(){
	var result = false;
	$('table').find('tr > td:first-child input:checkbox').each(function(){
		if(this.checked){
			result = true;
		}
	});
	return result;
}
function send_coupon(){
	if(checkSelect()){
		$("#form").submit();
	}else{
		alert('请选择正确的用户进行发放');
	}
}
</script>
</body>
</html>
